PROJECT(k3d)

# Configure CMake ...
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1 FATAL_ERROR)
CMAKE_POLICY(SET CMP0003 OLD)

SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

INCLUDE(K3DOutOfSourceBuild) # Disallow in-source builds
INCLUDE(K3DCompileResource)
INCLUDE(K3DGenerateDEF) # Convenience macro for linking Win32 DLLs using MSVC
INCLUDE(K3DDependencies)
INCLUDE(K3DWordSize) # Detect 32/64 bit platform
INCLUDE(K3DCompiler) # Detect problematic compilers

# Set the K-3D version
SET(K3D_MAJOR_VERSION 0)
SET(K3D_MINOR_VERSION 8)
SET(K3D_RELEASE_VERSION 0)
SET(K3D_BUILD_VERSION 3)
SET(K3D_SO_VERSION 1)

SET(K3D_PACKAGE k3d)
SET(K3D_VERSION ${K3D_MAJOR_VERSION}.${K3D_MINOR_VERSION}.${K3D_RELEASE_VERSION}.${K3D_BUILD_VERSION})
SET(K3D_HOST ${CMAKE_SYSTEM} ${CMAKE_SYSTEM_PROCESSOR})
SET(K3D_COPYRIGHT "Copyright (c) 1995-2010, Timothy M. Shead.	All Rights Reserved.")

# Run tests to find external packages ...
INCLUDE(K3DFind3ds)
INCLUDE(K3DFindCairomm)
INCLUDE(K3DFindCARVE)
INCLUDE(K3DFindCGAL)
INCLUDE(K3DFindCollada)
INCLUDE(K3DFindDBus)
INCLUDE(K3DFindFreetype2)
INCLUDE(K3DFindGlibmm)
INCLUDE(K3DFindGMM)
INCLUDE(K3DFindGnomeVFS)
INCLUDE(K3DFindGooglePerftools)
INCLUDE(K3DFindGtkGLExt)
INCLUDE(K3DFindGtkmm)
INCLUDE(K3DFindGtkSourceView)
INCLUDE(K3DFindGTS)
INCLUDE(K3DFindImageMagick)
INCLUDE(K3DFindInotify)
INCLUDE(K3DFindIntl)
INCLUDE(K3DFindJPEG)
INCLUDE(K3DFindODE)
INCLUDE(K3DFindOpenCascade)
INCLUDE(K3DFindOpenEXR)
INCLUDE(K3DFindOpenGL)
INCLUDE(K3DFindOSMesa)
INCLUDE(K3DFindPNG)
INCLUDE(K3DFindPython)
INCLUDE(K3DFindSigC)
INCLUDE(K3DFindSuperLU)
INCLUDE(K3DFindTBB)
INCLUDE(K3DFindTIFF)
INCLUDE(K3DFindXML)
INCLUDE(K3DFindZlib)

FIND_PACKAGE(Aqsis NO_MODULE QUIET)
FIND_PACKAGE(Qt4 4.6.2 COMPONENTS QtCore QtGui QtScript)
FIND_PACKAGE(K3DAsciiDoc)

# Setup platform-specific defaults ...
IF(WIN32 AND MSVC)
	SET(K3D_ENABLE_SYMBOL_VISIBILITY_DEFAULT ON)
ELSE()
	SET(K3D_ENABLE_SYMBOL_VISIBILITY_DEFAULT OFF)
ENDIF()

IF(Aqsis_FOUND AND QT4_FOUND)
	SET(K3D_QT_AQSIS_FOUND TRUE)
ELSE()
	SET(K3D_QT_AQSIS_FOUND FALSE)
ENDIF()

IF(K3D_OSMESA_FOUND AND QT4_FOUND)
	SET(K3D_QT_OSMESA_FOUND TRUE)
ELSE()
	SET(K3D_QT_OSMESA_FOUND FALSE)
ENDIF()

OPTION(K3D_BUILD_3DS_IO_MODULE "Build the 3ds_io module" ${K3D_3DS_FOUND})
OPTION(K3D_BUILD_ADVANCED_OPENGL_PAINTERS_MODULE "Build the advanced OpenGL mesh painters module" ON)
OPTION(K3D_BUILD_ANIMATION_MODULE "Build the animation module" ON)
OPTION(K3D_BUILD_ANNOTATION_MODULE "Build the annotation module" ${K3D_FREETYPE2_FOUND})
OPTION(K3D_BUILD_AQSIS_MODULE "Build the embedded Aqsis render engine module" ${Aqsis_FOUND})
OPTION(K3D_BUILD_ARRAY_MODULE "Build the array module" ON)
OPTION(K3D_BUILD_BICUBIC_PATCH_MODULE "Build the bicubic patch module" ON)
OPTION(K3D_BUILD_BILINEAR_PATCH_MODULE "Build the bilinear patch module" ON)
OPTION(K3D_BUILD_BITMAP_MODULE "Build the bitmap module" ON)
OPTION(K3D_BUILD_BLOBBY_MODULE "Build the blobby module" ON)
OPTION(K3D_BUILD_BUNDLED_RENDERMAN_ENGINES_MODULE "Provides integration with RenderMan-compatible render engines that are bundled with K-3D." OFF)
OPTION(K3D_BUILD_CARVE_MODULE "Build the CARVE module" ${K3D_CARVE_FOUND})
OPTION(K3D_BUILD_CGAL_MODULE "Build the CGAL module" ${K3D_CGAL_FOUND})
OPTION(K3D_BUILD_CLOTH_MODULE "Build the cloth module" ON)
OPTION(K3D_BUILD_COLLADA_IO_MODULE "Build the COLLADA module" ${K3D_COLLADA_FOUND})
OPTION(K3D_BUILD_COMPIZ_MODULE "Build the Compiz module" ${K3D_DBUS_FOUND})
OPTION(K3D_BUILD_CORE_MODULE "Build the core module" ON)
OPTION(K3D_BUILD_CUDA_MODULE "Build the cuda module" OFF)
OPTION(K3D_BUILD_DEFORMATION_MODULE "Build the mesh deformation module" ON)
OPTION(K3D_BUILD_DEVELOPMENT_MODULE "Build the development module" ON)
OPTION(K3D_BUILD_DOUBLE_MODULE "Build the double module" ON)
OPTION(K3D_BUILD_EULER_OPERATIONS_MODULE "Build the module that exposes the Euler mesh operations as mesh modifiers" OFF)
OPTION(K3D_BUILD_FILE_MAGIC_MODULE "Build the file-identification-magic module" ON)
OPTION(K3D_BUILD_FREETYPE2_MODULE "Build the freetype2 module" ON)
OPTION(K3D_BUILD_GLX_MODULE "Build the GLX offscreen rendering module" OFF)
OPTION(K3D_BUILD_GNOME_MODULE "Build the GNOME integration module" ${K3D_GNOME_VFS_FOUND})
OPTION(K3D_BUILD_GOOGLE_PERFTOOLS_MODULE "Build the Google Perftools profiling module" ${K3D_GOOGLE_PERFTOOLS_FOUND})
OPTION(K3D_BUILD_GRAPHVIZ_MODULE "Build the GraphViz integration module" ON)
OPTION(K3D_BUILD_GTS_IO_MODULE "Build the GNU Triangulated Surfaces file format module" ON)
OPTION(K3D_BUILD_GTS_MODULE "Build the GNU Triangulated Surfaces module" ${K3D_GTS_FOUND})
OPTION(K3D_BUILD_HIGHLIGHTING_MODULE "Build the user interface 'highlighting' module" ON)
OPTION(K3D_BUILD_IGES_IO_MODULE "Build the IGES file format module" ON)
OPTION(K3D_BUILD_IMAGEMAGICK_IO_MODULE "Build the ImageMagick file format module" ${K3D_IMAGEMAGICK_FOUND})
OPTION(K3D_BUILD_INDIGO_MODULE "Build the Indigo render engine integration module" ON)
OPTION(K3D_BUILD_INOTIFY_MODULE "Build the inotify file change notification module" ${K3D_INOTIFY_FOUND})
OPTION(K3D_BUILD_JPEG_IO_MODULE "Build the jpeg file format module" ${K3D_JPEG_FOUND})
OPTION(K3D_BUILD_K3D_IO_MODULE "Build the K-3D file format module" ON)
OPTION(K3D_BUILD_LINEAR_CURVE_MODULE "Build the linear curve module" ON)
OPTION(K3D_BUILD_LIPSYNC_MODULE "Build the lip synchronization tools module" ON)
OPTION(K3D_BUILD_LSYSTEM_MODULE "Build the l-system parser module" ON)
OPTION(K3D_BUILD_LUXRENDER_MODULE "Build the Luxrender render enegine integration module" ON)
OPTION(K3D_BUILD_MATRIX_MODULE "Build the matrix operations module" ON)
OPTION(K3D_BUILD_MD2_IO_MODULE "Build the md2 io module" ON)
OPTION(K3D_BUILD_MESH_ATTRIBUTES_MODULE "Build the mesh attributes module" ON)
OPTION(K3D_BUILD_MESH_INSTANCE_MODULE "Build the mesh-instance module" ON)
OPTION(K3D_BUILD_MESH_MODULE "Build the mesh module" ON)
OPTION(K3D_BUILD_NGUI_ABOUT_MODULE "Build the user interface 'about' dialog module" ON)
OPTION(K3D_BUILD_NGUI_ANIMATION_TIMELINE_PANEL_MODULE "Build the experimental animation timeline panel module" ON)
OPTION(K3D_BUILD_NGUI_ASSIGN_HOTKEYS_MODULE "Build the user interface 'assign hotkeys' module" ON)
OPTION(K3D_BUILD_NGUI_ATK_EVENT_RECORDER_MODULE "Build the user interface ATK 'event recorder' module" OFF)
OPTION(K3D_BUILD_NGUI_KNOT_VECTOR_CONTROL_MODULE "Build the custom knot-vector property control module" ON)
OPTION(K3D_BUILD_NGUI_LEARNING_MODULE "Build the user interface learning (tutorial) dialog module" ON)
OPTION(K3D_BUILD_NGUI_LOG_MODULE "Build the user interface log window module" ON)
OPTION(K3D_BUILD_NGUI_MATERIAL_MANAGER_PANEL_MODULE "Build the user interface manager manager panel module" OFF)
OPTION(K3D_BUILD_NGUI_MESH_CONTROL_MODULE "Build the mesh property control module" ON)
OPTION(K3D_BUILD_NGUI_MODULE "Build the standard graphical user interface module" ON)
OPTION(K3D_BUILD_NGUI_MORPH_POINTS_PAGE_MODULE "Build the MorphPoints custom property page module" ON)
OPTION(K3D_BUILD_NGUI_NODE_LIST_PANEL_MODULE "Build the user interface node list panel module" ON)
OPTION(K3D_BUILD_NGUI_NODE_PROPERTIES_PANEL_MODULE "Build the user interface node properties panel module" ON)
OPTION(K3D_BUILD_NGUI_OPENGL_DIALOG_MODULE "Build the user interface OpenGL information dialog module" ON)
OPTION(K3D_BUILD_NGUI_PARENT_TOOL_MODULE "Build the user interface 'parent tool' module" ON)
OPTION(K3D_BUILD_NGUI_PIPELINE_PANEL_MODULE "Build the user interface pipeline display panel module" ON)
OPTION(K3D_BUILD_NGUI_PIPELINE_PROFILER_PANEL_MODULE "Build the user interface pipeline profiler panel module" ON)
OPTION(K3D_BUILD_NGUI_PYTHON_SHELL_MODULE "Build the interactive Python shell module" ON)
OPTION(K3D_BUILD_NGUI_RECTANGLE_CONTROL_MODULE "Build the custom rectangle property control module" ON)
OPTION(K3D_BUILD_NGUI_RENDER_REGION_TOOL_MODULE "Build the user interface 'render region tool' module" ON)
OPTION(K3D_BUILD_NGUI_SELECTION_CONTROL_MODULE "Build the selection property control module" ON)
OPTION(K3D_BUILD_NGUI_SNAP_TOOL_MODULE "Build the user interface 'snap tool' module" ON)
OPTION(K3D_BUILD_NGUI_SPACE_NAVIGATOR_MODULE "Build the SpaceNavigator 3D mouse integration module" OFF)
OPTION(K3D_BUILD_NGUI_TEXT_EDITOR_MODULE "Build the user interface text editor module" ON)
OPTION(K3D_BUILD_NGUI_TIMELINE_PANEL_MODULE "Build the user interface timeline panel module" ON)
OPTION(K3D_BUILD_NGUI_TOOLBAR_PANEL_MODULE "Build the user interface toolbar panel module" ON)
OPTION(K3D_BUILD_NGUI_TOOL_PROPERTIES_PANEL_MODULE "Build the user interface tool properties panel module" ON)
OPTION(K3D_BUILD_NGUI_UNDO_TREE_PANEL_MODULE "Build the user interface undo panel module" ON)
OPTION(K3D_BUILD_NGUI_UV_EDITOR_PANEL_MODULE "Build the user interface UV editor panel module" OFF)
OPTION(K3D_BUILD_NUI_MODULE "Build the Null User Interface module" ON)
OPTION(K3D_BUILD_NURBS_MODULE "Build the NURBS module" ON)
OPTION(K3D_BUILD_NURBS_SOURCES_MODULE "Build the NURBS sources module" ON)
OPTION(K3D_BUILD_OBJ_IO_MODULE "Build the Wavefront .obj file format module" ON)
OPTION(K3D_BUILD_ODE_MODULE "Build the Open Dynamics Engine (ODE) integration module" ${K3D_ODE_FOUND})
OPTION(K3D_BUILD_OGRE_IO_MODULE "Build the Object-oriented Graphics Engine (OGRE) file I/O module" ON)
OPTION(K3D_BUILD_OPENCASCADE_MODULE "Build the OpenCascade module" ${K3D_OPENCASCADE_FOUND})
OPTION(K3D_BUILD_OPENEXR_IO_MODULE "Build the OpenEXR file format module" ${K3D_OPENEXR_FOUND})
OPTION(K3D_BUILD_OPENGL_MODULE "Build the OpenGL integration module" ON)
OPTION(K3D_BUILD_OSMESA_MODULE "Build the Offscreen Mesa integration module" ${K3D_OSMESA_FOUND})
OPTION(K3D_BUILD_OSX_MODULE "Build the Mac OSX integration module" ${APPLE})
OPTION(K3D_BUILD_PARTICLE_MODULE "Build the point group module" ON)
OPTION(K3D_BUILD_PDIFF_MODULE "Build the perceptual-diff module" ON)
OPTION(K3D_BUILD_PIXIE_MODULE "Build the Pixie render engine integration module" ON)
OPTION(K3D_BUILD_PLOT_MODULE "Build the function-plot module" ON)
OPTION(K3D_BUILD_PLY_IO_MODULE "Build the Stanford .ply file format module" ON)
OPTION(K3D_BUILD_PNG_IO_MODULE "Build the PNG file format module" ON)
OPTION(K3D_BUILD_POLYHEDRON_MODULE "Build the polyhedron module" ON)
OPTION(K3D_BUILD_POLYHEDRON_SOURCES_MODULE "Build the polyhedron sources module" ON)
OPTION(K3D_BUILD_PYTHON_MODULE "Build the Python scripting language module" ON)
OPTION(K3D_BUILD_PYUI_MODULE "Build the Python user interface plugin" ON)
OPTION(K3D_BUILD_QSLIM_MODULE "Build the qslim module" ON)
OPTION(K3D_BUILD_QTUI_ABOUT_DIALOG_MODULE "Build the Qt user interface 'about' dialog module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_AQSIS_MODE_MODULE "Build the Qt-Aqsis integration mode module" ${K3D_QT_AQSIS_FOUND})
OPTION(K3D_BUILD_QTUI_AQSIS_MODULE "Build the Qt-Aqsis integration module" ${K3D_QT_AQSIS_FOUND})
OPTION(K3D_BUILD_QTUI_BOOLEAN_MODULE "Build the Qt graphical user interface boolean property widget module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_COLOR_MODULE "Build the Qt graphical user interface color property widget module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_DEFAULT_MODE_MODULE "Build the Qt graphical user interface default mode module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_JAVASCRIPT_SHELL_MODULE "Build the Qt graphical user interface interactive JavaScript shell module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_LOG_MODULE "Build the Qt user interface log window module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_MATRIX_MODULE "Build the Qt graphical user interface matrix property widget module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_MODULE "Build the Qt graphical user interface module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_MOVE_MODE_MODULE "Build the user interface mode to move components" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_NODE_LIST_MODULE "Build the Qt graphical user interface node list module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_NODE_PROPERTIES_MODULE "Build the Qt graphical user interface node properties module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_OPENGL_MODULE "Build the Qt graphical user interface OpenGL-test module" ${K3D_QT_OSMESA_FOUND})
OPTION(K3D_BUILD_QTUI_PATH_MODULE "Build the Qt graphical user interface filesystem path property widget module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_PROGRAMMABLE_MODE_MODULE "Build the Qt graphical user interface programmable mode module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_STRING_MODULE "Build the Qt graphical user interface string property widget module" ${QT4_FOUND})
OPTION(K3D_BUILD_QTUI_TEXT_EDITOR_MODULE "Build the Qt graphical user interface text editor module" ${QT4_FOUND})
OPTION(K3D_BUILD_QUADRICS_MODULE "Build the quadrics module" ON)
OPTION(K3D_BUILD_REFERENCE_OPENGL_PAINTERS_MODULE "Build the reference OpenGL mesh painters module" ON)
OPTION(K3D_BUILD_RENDERMAN_ENGINES_MODULE "Provides integration with many RenderMan-compatible render engines." ON)
OPTION(K3D_BUILD_RENDERMAN_MODULE "Build the RenderMan integration module" ON)
OPTION(K3D_BUILD_RENDERMAN_PAINTERS_MODULE "Build the RenderMan mesh painters module" ON)
OPTION(K3D_BUILD_RELEASE_MODULE "Build the release nag-messages module" ON)
OPTION(K3D_BUILD_SCRIPTED_PLUGINS_MODULE "Build the scripted plugins module" ON)
OPTION(K3D_BUILD_SCRIPTING_MODULE "Build the scripting module" ON)
OPTION(K3D_BUILD_SELECTION_MODULE "Build the selection module" ON)
OPTION(K3D_BUILD_SOLAR_MODULE "Build the solar module" ON)
OPTION(K3D_BUILD_STL_IO_MODULE "Build the STL file format module" ON)
OPTION(K3D_BUILD_SUBDIVISION_SURFACE_MODULE "Build the subdivision surface module" ON)
OPTION(K3D_BUILD_SVG_IO_MODULE "Build the SVG file format module" ON)
OPTION(K3D_BUILD_TEST_MODULE "Build the regression test module" ON)
OPTION(K3D_BUILD_TIFF_IO_MODULE "Build the TIFF file format module" ON)
OPTION(K3D_BUILD_TIME_MODULE "Build the time source module" ON)
OPTION(K3D_BUILD_UNIFORM_POLYHEDRON_MODULE "Build the uniform polyhedron source module" ON)
OPTION(K3D_BUILD_VIRTUAL_OFFSCREEN_MODULE "Build the virtual offscreen OpenGL rendering module" OFF)
OPTION(K3D_BUILD_VIRTUAL_OPENGL_PAINTERS_MODULE "Build virtual OpenGL painters modules" ON)
OPTION(K3D_BUILD_WGL_MODULE "Build the Windows offscreen rendering module" ${WIN32})
OPTION(K3D_BUILD_WINDOWS_MODULE "Build the Windows integration module" ${WIN32})
OPTION(K3D_BUILD_XTRACKCAD_MODULE "Build the XTrackCAD Model Railroad integration module" ON)
OPTION(K3D_BUILD_YAFRAY_MODULE "Build the YAFRAY render engine integration module" ON)

OPTION(K3D_BUILD_DOCS "Build the documentation" ON)

OPTION(K3D_ENABLE_OSX_BUNDLE "Package K-3D as an OSX bundle (ignored on other platforms)." OFF)
OPTION(K3D_ENABLE_DISTRIBUTION "Enable distribution targets." OFF)
OPTION(K3D_ENABLE_NLS "Build K-3D with native language support" ON)
OPTION(K3D_ENABLE_PARALLEL "Enable parallel computation using the Threaded Building Blocks library." OFF)
OPTION(K3D_ENABLE_PROFILING "Enable code profiling using Google Perftools." OFF)
OPTION(K3D_ENABLE_PYTHON "Build K-3D with Python support" ON)
OPTION(K3D_ENABLE_SYMBOL_VISIBILITY "Minimize the number of symbols exported from shared libraries." ${K3D_ENABLE_SYMBOL_VISIBILITY_DEFAULT})
OPTION(K3D_ENABLE_TESTING "Build the K-3D regression test suite." OFF)

# Find Boost - this logic must follow all user-definable options 
SET(K3D_BOOST_COMPONENTS date_time program_options regex unit_test_framework)
IF(K3D_ENABLE_PYTHON)
	LIST(APPEND K3D_BOOST_COMPONENTS python)
ENDIF()
IF(K3D_BUILD_COLLADA_IO_MODULE)
	LIST(APPEND K3D_BOOST_COMPONENTS filesystem system)
ENDIF()
IF(K3D_BUILD_CGAL_MODULE)
	LIST(APPEND K3D_BOOST_COMPONENTS thread)
ENDIF()
INCLUDE(K3DFindBoost)

# Find required external packages
K3D_CHECK("K-3D" REQUIRES Boost_FOUND RESOURCE "Boost" URL "http://www.boost.org" MESSAGE "Note: K-3D requires many of the compiled Boost libraries, which may be distributed separately on some systems.")
K3D_CHECK("K-3D" REQUIRES K3D_GLIBMM_FOUND RESOURCE "glibmm" URL "http://gtkmm.org")
K3D_CHECK("K-3D" REQUIRES K3D_OPENGL_FOUND RESOURCE "OpenGL" URL "http://opengl.org")
K3D_CHECK("K-3D" REQUIRES K3D_SIGC_FOUND RESOURCE "libsigc++" URL "http://libsigc.sourceforge.net")
K3D_CHECK("K-3D" REQUIRES K3D_XML_FOUND RESOURCE "XML parser" URL "http://xmlsoft.org")
K3D_CHECK("K-3D" REQUIRES K3D_ZLIB_FOUND RESOURCE "zlib" URL "http://www.zlib.net")

K3D_CHECK(K3D_BUILD_3DS_IO_MODULE REQUIRES K3D_3DS_FOUND RESOURCE "lib3ds")
K3D_CHECK(K3D_BUILD_ANNOTATION_MODULE REQUIRES K3D_FREETYPE2_FOUND RESOURCE "freetype2")
K3D_CHECK(K3D_BUILD_AQSIS_MODULE REQUIRES Aqsis_FOUND MESSAGE "To build this module you need to set Aqsis_DIR to the path to an Aqsis build directory.")
K3D_CHECK(K3D_BUILD_CARVE_MODULE REQUIRES K3D_CARVE_FOUND RESOURCE "CARVE")
K3D_CHECK(K3D_BUILD_CGAL_MODULE REQUIRES K3D_CGAL_FOUND RESOURCE "CGAL")
K3D_CHECK(K3D_BUILD_COLLADA_MODULE REQUIRES K3D_COLLADA_FOUND RESOURCE "Collada DOM")
K3D_CHECK(K3D_BUILD_COMPIZ_MODULE REQUIRES K3D_DBUS_FOUND RESOURCE "libdbus")
K3D_CHECK(K3D_BUILD_FREETYPE2_MODULE REQUIRES K3D_FREETYPE2_FOUND RESOURCE "freetype2")
K3D_CHECK(K3D_BUILD_GNOME_MODULE REQUIRES K3D_GNOME_VFS_FOUND RESOURCE "Gnome VFS")
K3D_CHECK(K3D_BUILD_GOOGLE_PERFTOOLS_MODULE REQUIRES K3D_ENABLE_PROFILING)
K3D_CHECK(K3D_BUILD_GTS_MODULE REQUIRES K3D_GTS_FOUND RESOURCE "GNU Triangulated Surface")
K3D_CHECK(K3D_BUILD_IMAGEMAGICK_IO_MODULE REQUIRES K3D_IMAGEMAGICK_FOUND RESOURCE "ImageMagick")
K3D_CHECK(K3D_BUILD_JPEG_IO_MODULE REQUIRES K3D_JPEG_FOUND RESOURCE "JPEG")
K3D_CHECK(K3D_BUILD_NGUI_ABOUT_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_ANIMATION_TIMELINE_PANEL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_ASSIGN_HOTKEYS_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_ATK_EVENT_RECORDER_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_KNOT_VECTOR_CONTROL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_LEARNING_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_LOG_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_MESH_CONTROL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_MODULE REQUIRES K3D_GTKGLEXT_FOUND RESOURCE "gtkglext")
K3D_CHECK(K3D_BUILD_NGUI_MODULE REQUIRES K3D_GTKGLEXT_FOUND RESOURCE "gtkglext")
K3D_CHECK(K3D_BUILD_NGUI_MODULE REQUIRES K3D_GTKMM_FOUND RESOURCE "gtkmm")
K3D_CHECK(K3D_BUILD_NGUI_MODULE REQUIRES K3D_GTKMM_FOUND RESOURCE "gtkmm")
K3D_CHECK(K3D_BUILD_NGUI_MORPH_POINTS_PAGE_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_NODE_HISTORY_PANEL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_NODE_LIST_PANEL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_NODE_PROPERTIES_PANEL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_OPENGL_DIALOG_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_PARENT_TOOL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_PIPELINE_PANEL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_PIPELINE_PANEL_MODULE REQUIRES K3D_CAIROMM_FOUND RESOURCE "cairomm")
K3D_CHECK(K3D_BUILD_NGUI_PIPELINE_PANEL_MODULE REQUIRES K3D_CAIROMM_FOUND RESOURCE "cairomm")
K3D_CHECK(K3D_BUILD_NGUI_PIPELINE_PROFILER_PANEL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_PYTHON_SHELL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_PYTHON_SHELL_MODULE REQUIRES K3D_ENABLE_PYTHON)
K3D_CHECK(K3D_BUILD_NGUI_PYTHON_SHELL_MODULE REQUIRES K3D_ENABLE_PYTHON)
K3D_CHECK(K3D_BUILD_NGUI_RECTANGLE_CONTROL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_RENDER_REGION_TOOL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_SELECTION_CONTROL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_SNAP_TOOL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_SPACE_NAVIGATOR_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_TEXT_EDITOR_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_TIMELINE_PANEL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_TOOLBAR_PANEL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_TOOL_PROPERTIES_PANEL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_UNDO_TREE_PANEL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_NGUI_UV_EDITOR_PANEL_MODULE REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_CHECK(K3D_BUILD_OPENCASCADE_MODULE REQUIRES K3D_OPENCASCADE_FOUND RESOURCE "OpenCASCADE")
K3D_CHECK(K3D_BUILD_OPENEXR_IO_MODULE REQUIRES K3D_OPENEXR_FOUND RESOURCE "OpenEXR")
K3D_CHECK(K3D_BUILD_OSMESA_MODULE REQUIRES K3D_OSMESA_FOUND RESOURCE "OSMesa")
K3D_CHECK(K3D_BUILD_PGP_REMESH_MODULE REQUIRES K3D_GMM_FOUND RESOURCE "gmm")
K3D_CHECK(K3D_BUILD_PNG_IO_MODULE REQUIRES K3D_PNG_FOUND RESOURCE "PNG")
K3D_CHECK(K3D_BUILD_PYTHON_MODULE REQUIRES K3D_ENABLE_PYTHON)
K3D_CHECK(K3D_BUILD_PYUI_MODULE REQUIRES K3D_ENABLE_PYTHON)
K3D_CHECK(K3D_BUILD_QTUI_ABOUT_DIALOG_MODULE REQUIRES K3D_BUILD_QTUI_MODULE)
K3D_CHECK(K3D_BUILD_QTUI_AQSIS_MODULE REQUIRES Aqsis_FOUND K3D_BUILD_QTUI_MODULE MESSAGE "To build this module you need to set Aqsis_DIR to the path to an Aqsis build directory.")
K3D_CHECK(K3D_BUILD_QTUI_AQSIS_MODE_MODULE REQUIRES Aqsis_FOUND K3D_BUILD_QTUI_MODULE MESSAGE "To build this module you need to set Aqsis_DIR to the path to an Aqsis build directory.")
K3D_CHECK(K3D_BUILD_QTUI_BOOLEAN_MODULE REQUIRES K3D_BUILD_QTUI_MODULE)
K3D_CHECK(K3D_BUILD_QTUI_COLOR_MODULE REQUIRES K3D_BUILD_QTUI_MODULE)
K3D_CHECK(K3D_BUILD_QTUI_DEFAULT_MODE_MODULE REQUIRES K3D_BUILD_QTUI_MODULE)
K3D_CHECK(K3D_BUILD_QTUI_JAVASCRIPT_SHELL_MODULE REQUIRES K3D_BUILD_QTUI_MODULE)
K3D_CHECK(K3D_BUILD_QTUI_LOG_MODULE REQUIRES K3D_BUILD_QTUI_MODULE)
K3D_CHECK(K3D_BUILD_QTUI_MATRIX_MODULE REQUIRES K3D_BUILD_QTUI_MODULE)
K3D_CHECK(K3D_BUILD_QTUI_MODULE REQUIRES QT4_FOUND RESOURCE "Qt4")
K3D_CHECK(K3D_BUILD_QTUI_MOVE_MODE_MODULE REQUIRES QT4_FOUND)
K3D_CHECK(K3D_BUILD_QTUI_NODE_LIST_MODULE REQUIRES QT4_FOUND)
K3D_CHECK(K3D_BUILD_QTUI_NODE_PROPERTIES_MODULE REQUIRES QT4_FOUND)
K3D_CHECK(K3D_BUILD_QTUI_OPENGL_MODULE REQUIRES K3D_BUILD_QTUI_MODULE K3D_BUILD_OSMESA_MODULE)
K3D_CHECK(K3D_BUILD_QTUI_PATH_MODULE REQUIRES K3D_BUILD_QTUI_MODULE)
K3D_CHECK(K3D_BUILD_QTUI_PROGRAMMABLE_MODE_MODULE REQUIRES K3D_BUILD_QTUI_MODULE)
K3D_CHECK(K3D_BUILD_QTUI_STRING_MODULE REQUIRES K3D_BUILD_QTUI_MODULE)
K3D_CHECK(K3D_BUILD_QTUI_TEXT_EDITOR_MODULE REQUIRES K3D_BUILD_QTUI_MODULE)
K3D_CHECK(K3D_BUILD_TIFF_IO_MODULE REQUIRES K3D_TIFF_FOUND RESOURCE "libtiff")
K3D_CHECK(K3D_ENABLE_NLS REQUIRES K3D_INTL_FOUND RESOURCE "intl")
K3D_CHECK(K3D_ENABLE_PARALLEL REQUIRES K3D_TBB_FOUND RESOURCE "Threading Building Blocks" URL "http://threadingbuildingblocks.org")
K3D_CHECK(K3D_ENABLE_PROFILING REQUIRES K3D_GOOGLE_PERFTOOLS_FOUND RESOURCE "Google Perftools" URL "http://code.google.com/p/google-perftools")
K3D_CHECK(K3D_ENABLE_PYTHON REQUIRES K3D_PYTHON_FOUND RESOURCE "Python")

# Setup testing
SET(BUILD_TESTING ${K3D_ENABLE_TESTING} CACHE INTERNAL "" FORCE)
INCLUDE(CTest)
IF(K3D_ENABLE_TESTING)
	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake @ONLY)
ENDIF()

# Capture system configuration
INCLUDE(K3DSystemConfiguration)

# Win32 configuration
IF(WIN32 AND NOT MSVC)
	SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-runtime-pseudo-reloc" CACHE STRING "" FORCE)
	SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-runtime-pseudo-reloc -Wl,--export-all-symbols" CACHE STRING "" FORCE)
ENDIF()

# Setup output directories ...
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${k3d_BINARY_DIR}/bin)

SET(K3D_LIBDIR lib) # Allows us to handle 64-bit libs if/when it becomes necessary.

IF(APPLE AND K3D_ENABLE_OSX_BUNDLE)
	SET(K3D_BUNDLE_DIRECTORY ${k3d_BINARY_DIR}/K-3D.app/Contents)
	SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${K3D_BUNDLE_DIRECTORY}/${K3D_LIBDIR})
	SET(K3D_RUNTIME_OUTPUT_DIRECTORY ${K3D_BUNDLE_DIRECTORY}/MacOS)
	SET(K3D_MODULE_OUTPUT_DIRECTORY ${K3D_BUNDLE_DIRECTORY}/${K3D_LIBDIR}/k3d/plugins)
	SET(K3D_SHARE_OUTPUT_DIRECTORY ${K3D_BUNDLE_DIRECTORY}/share)
ELSEIF(WIN32)
	SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${k3d_BINARY_DIR}/bin)
	SET(K3D_RUNTIME_OUTPUT_DIRECTORY ${k3d_BINARY_DIR}/bin)
	SET(K3D_MODULE_OUTPUT_DIRECTORY ${k3d_BINARY_DIR}/lib/${K3D_LIBDIR}/k3d/plugins)
	SET(K3D_SHARE_OUTPUT_DIRECTORY ${k3d_BINARY_DIR}/share)
ELSE()
	SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${k3d_BINARY_DIR}/${K3D_LIBDIR})
	SET(K3D_RUNTIME_OUTPUT_DIRECTORY ${k3d_BINARY_DIR}/bin)
	SET(K3D_MODULE_OUTPUT_DIRECTORY ${k3d_BINARY_DIR}/${K3D_LIBDIR}/k3d/plugins)
	SET(K3D_SHARE_OUTPUT_DIRECTORY ${k3d_BINARY_DIR}/share)
ENDIF()

# Setup subdirectories ...
K3D_ADD_SUBDIRECTORY(gendef REQUIRES MSVC)

ADD_SUBDIRECTORY(k3dsdk)
ADD_SUBDIRECTORY(resource-compiler)

ADD_SUBDIRECTORY(application)
ADD_SUBDIRECTORY(desktop)
ADD_SUBDIRECTORY(make-module-proxy)
ADD_SUBDIRECTORY(renderjob)
ADD_SUBDIRECTORY(renderframe)
ADD_SUBDIRECTORY(sl2xml)
ADD_SUBDIRECTORY(uuidgen)
ADD_SUBDIRECTORY(modules)
ADD_SUBDIRECTORY(share)

K3D_ADD_SUBDIRECTORY(tests REQUIRES K3D_ENABLE_TESTING)
K3D_ADD_SUBDIRECTORY(po REQUIRES K3D_ENABLE_NLS)

ADD_SUBDIRECTORY(bugs)
K3D_ADD_SUBDIRECTORY(docs REQUIRES K3D_BUILD_DOCS)
ADD_SUBDIRECTORY(web)

K3D_ADD_SUBDIRECTORY(distribution REQUIRES K3D_ENABLE_DISTRIBUTION)

# Hide some cruft ...
MARK_AS_ADVANCED(A2X_COMMAND)
MARK_AS_ADVANCED(AQSIS_COMMAND)
MARK_AS_ADVANCED(AQSL_COMMAND)
MARK_AS_ADVANCED(ASCIIDOC_COMMAND)
MARK_AS_ADVANCED(ASSISTANT_COMMAND)
MARK_AS_ADVANCED(ASTYLE_COMMAND)
MARK_AS_ADVANCED(Aqsis_DIR)
MARK_AS_ADVANCED(CMAKE_BACKWARDS_COMPATIBILITY)
MARK_AS_ADVANCED(CMAKE_EXECUTABLE_FORMAT)
MARK_AS_ADVANCED(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
MARK_AS_ADVANCED(CMAKE_OSX_ARCHITECTURES)
MARK_AS_ADVANCED(CMAKE_OSX_DEPLOYMENT_TARGET)
MARK_AS_ADVANCED(CMAKE_OSX_SYSROOT)
MARK_AS_ADVANCED(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
MARK_AS_ADVANCED(CMAKE_USE_CHRPATH)
MARK_AS_ADVANCED(CUDA_FOUND CUDA_COMPILER CUDA_RUNTIME_LIBRARY)
MARK_AS_ADVANCED(DART_TESTING_TIMEOUT)
MARK_AS_ADVANCED(DITZ_EXECUTABLE)
MARK_AS_ADVANCED(GDB_COMMAND)
MARK_AS_ADVANCED(GIT_COMMAND)
MARK_AS_ADVANCED(K3D_AQSIS_COMMAND)
MARK_AS_ADVANCED(K3D_BOOST_INCLUDE_DIR)
MARK_AS_ADVANCED(K3D_BOOST_LIBRARY_DIR)
MARK_AS_ADVANCED(K3D_BOOST_USE_MULTITHREADED)
MARK_AS_ADVANCED(K3D_ENABLE_PARALLEL)
MARK_AS_ADVANCED(K3D_ENABLE_PROFILING)
MARK_AS_ADVANCED(K3D_ENABLE_SYMBOL_VISIBILITY)
MARK_AS_ADVANCED(K3D_EXTRA_GDB_ARGUMENTS)
MARK_AS_ADVANCED(K3D_EXTRA_QT_PLUGINS)
MARK_AS_ADVANCED(K3D_GTK_DIR)
MARK_AS_ADVANCED(K3D_INTLTOOL_UPDATE)
MARK_AS_ADVANCED(K3D_MACPORTS_DIR)
MARK_AS_ADVANCED(K3D_MINGW_GCC)
MARK_AS_ADVANCED(K3D_MSGFMT)
MARK_AS_ADVANCED(K3D_MSGMERGE)
MARK_AS_ADVANCED(K3D_PYTHON_COMMAND)
MARK_AS_ADVANCED(K3D_PYTHON_LIBRARY)
MARK_AS_ADVANCED(K3D_SOURCEFORGE_USERNAME)
MARK_AS_ADVANCED(K3D_XGETTEXT)
MARK_AS_ADVANCED(MAKO_COMMAND)
MARK_AS_ADVANCED(QCOLLECTIONGENERATOR_COMMAND)
MARK_AS_ADVANCED(QHELPGENERATOR_COMMAND)
MARK_AS_ADVANCED(QT_MKSPECS_DIR)
MARK_AS_ADVANCED(QT_PLUGINS_DIR)
MARK_AS_ADVANCED(QT_QMAKE_EXECUTABLE)
MARK_AS_ADVANCED(QT_QTMOTIF_INCLUDE_DIR)
MARK_AS_ADVANCED(QT_QTMOTIF_LIBRARY_DEBUG)
MARK_AS_ADVANCED(QT_QTMOTIF_LIBRARY_RELEASE)
MARK_AS_ADVANCED(QT_X11_X11_LIBRARY)
MARK_AS_ADVANCED(QT_X11_Xext_LIBRARY)
MARK_AS_ADVANCED(QT_X11_m_LIBRARY)
MARK_AS_ADVANCED(RNDR_COMMAND)
MARK_AS_ADVANCED(RSVG_COMMAND)
MARK_AS_ADVANCED(SDRC_COMMAND)
